<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div></div>
    <button>后退</button>
    <script>
      // location.search返回参数时会把？一起返回
      console.log(location.search);
      //substr(截取开始位置，个数)截取返回的参数，去掉？，不写个数默认返回后面全部
      var params = location.search.substr(1);
      console.log(params);
      //利用 = 把字符串分割为数组
      var arr = params.split("=");
      console.log(arr);
      //获取元素并赋值
      var div = document.querySelector("div");
      div.innerHTML = arr[1];

      //根据用户设备返回对应页面
      /*       if (
        navigator.userAgent.match(
          /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i
        )
      ) {
        window.location.href = "index.html";
      } else {
        window.location.href = "Web APIs基础.html";
      } */

      //history对象
      var btn = document.querySelector("button");
      btn.addEventListener("click", function () {
        // history.back();
        history.go(-1);
      });
    </script>
  </body>
</html>
